package com.tedu.announce.service.impl;

import com.tedu.announce.mapper.AnnounceMapper;
import com.tedu.announce.pojo.dto.AnnounceQuery;
import com.tedu.announce.pojo.entity.Announce;
import com.tedu.announce.pojo.vo.AnnounceVO;
import com.tedu.announce.service.AnnounceService;
import com.tedu.user.pojo.dto.AnnounceSaveParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class announceServiceImpl implements AnnounceService {

    @Autowired
    private AnnounceMapper announceMapper;

    @Override
    public List<AnnounceVO> selectAnnounce(AnnounceQuery announceQuery) {
        log.debug("查询公告业务-入参：{}", announceQuery);
        List<AnnounceVO> announceVOList = announceMapper.select(announceQuery);
        log.debug("查询公告业务-出参：{}", announceVOList);
        return announceVOList;
    }

    @Override
    public void deleteAnnounce(Integer id) {
        log.debug("删除公告业务-入参:{}", id);
        announceMapper.delete(id);
    }

    @Override
    public void addAnnounce(AnnounceSaveParam announceSaveParam) {
        log.debug("新增公告业务-入参：{}", announceSaveParam);
        Announce announce = new Announce();
        BeanUtils.copyProperties(announceSaveParam, announce);
        if (announce.getId() == null) {
            announceMapper.insert(announce);
        } else {
            announce.setUpdateTime(new Date());
            announceMapper.update(announce);
        }
    }
}
